package org.Leetcode;

import java.util.HashSet;
import java.util.Set;

public class E04Leetcode217 {
    public boolean containsDuplicate(int[] nums) {
        return containsDuplicateBySet(nums);
    }
    public boolean containsDuplicateBySet(int[] nums) {
        int len = nums.length;
        if (len < 2) {
            return false;
        }
        Set<Integer> set = new HashSet();
        for (int i = 0; i < len; i++) {
            if (!set.add(nums[i])) {
                return true;
            }
        }
        return false;
    }

}
